<?php
/**
 * Description
 *
 * PHP version 7
 *
 * @category Custom
 * @package  Custom
 * @author   ryu <mo5467@126.com>
 * @date     2020-04-28 22:44:28
 * @lastTime 2020-05-01 23:10:03
 * @license  https://opensource.org/licenses/MIT MIT License
 * @link     none
 */
namespace Design\Behavioral\Memento;

class State
{

    private $state;
    const STATE_CREATED  = 'created';
    const STATE_OPENED   = 'opened';
    const STATE_ASSIGNED = 'assigned';
    const STATE_CLOSED   = 'closed';

    private static $validStates = [
        self::STATE_CREATED,
        self::STATE_OPENED,
        self::STATE_ASSIGNED,
        self::STATE_CLOSED,
    ];


    public function __construct(string $state)
    {
        self::ensureIsValidState($state);

        $this->state = $state;

    }//end __construct()


    private static function ensureIsValidState(string $state)
    {
        if (!in_array($state, self::$validStates)) {
            throw new \InvalidArgumentException('Invalid state given');
        }

    }//end ensureIsValidState()


    public function __toString() : string
    {
        return $this->state;

    }//end __toString()


}//end class
